//
//  DYZChooseBrandController.m
//  发布车源
//
//  Created by xmy on 16/8/19.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "DYZChooseBrandController.h"
#import "DSHTTPClient.h"
#import "DYZChooseSeriesController.h"
#import "DYZCarSourceDetailController.h"
#import "UIColor+Addition.h"
static NSString *cellid = @"cellid";

@interface DYZChooseBrandController ()
@property(nonatomic,strong)NSArray *loadData;
@property(nonatomic,strong)NSArray *brandIds;
@end

@implementation DYZChooseBrandController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self type];
//    [self search];
    self.navigationItem.title = @"选择品牌";
    
    //注册
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    
    self.tableView.rowHeight = 45;
    
     self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
   
}
//解析车系数据
- (void)type{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    //"account":"13800111100","pasword":"123456"
    [param setValue:@"1" forKey:@"accountid"];
    [param setValue:@"3" forKey:@"cartype"];
    
    [DSHTTPClient postUrlString:@"http://iosapi.itcast.cn/car/cartypelist.json.php" withParam:param withSuccessBlock:^(NSDictionary * data) {
    
        
        NSDictionary *dict = [data objectForKey:@"data"];
        
        NSMutableArray *array = [NSMutableArray array];
       
        
        NSArray *arr = [dict objectForKey:@"high"];
        
        for (NSDictionary *dict1 in arr) {
            
            NSString *str = [dict1 objectForKey:@"name"];
            
            [array addObject:str];
           
        }
        
//        NSLog(@"%@",array);
      
        self.loadData = array.copy;
        
        [self.tableView reloadData];
        
    } withFailedBlock:^(NSError *error) {
        NSLog(@"%@",error);
    } withErrorBlock:^(NSString *message) {
        NSLog(@"%@",message);
    }];
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.loadData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
    
    cell.textLabel.text = self.loadData[indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    [cell.textLabel setTextColor:[UIColor colorWithHex:0x333333]];
    return cell;

}

//cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //取消点击效果
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    DYZChooseSeriesController *series = [[DYZChooseSeriesController alloc]init];
    
    series.name = self.loadData[indexPath.row];
    
        if(indexPath.row == 0 || indexPath.row == 2)
        {
            series.brandId = @"BD1001";
            
        }else if(indexPath.row == 1 || indexPath.row == 3){
            
            series.brandId = @"BD1002";
        }
    
    [self.navigationController pushViewController:series animated:YES];
            
}

@end
